﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using whatpricemyhouse.LINQ;

namespace whatpricemyhouse.Admin
{
    public partial class editBuySetting : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Admin/Default.aspx");
            }
            if (!User.IsInRole("administrator "))
            {
                Response.Redirect("~/Admin/Default.aspx");
            }
        }
        DataControllerDataContext dcdc = new DataControllerDataContext();
        protected void PRAddButton_Click(object sender, EventArgs e)
        {
            String prName = PRNameTxt.Text;
            String prValue = PRValueTxt.Text;
            String prDec = PRDescTxt.Text;

            
            price_range_table prt = new price_range_table();
            prt.PRID = Guid.NewGuid().ToString();
            prt.PRName = prName;
            try
            {
                prt.PRValue = Double.Parse(prValue);
                prt.PRDesc = prDec;
                dcdc.price_range_tables.InsertOnSubmit(prt);
                dcdc.SubmitChanges();
                GridView1.DataBind();
                ValueErrorLabel.Text = "";
            }
            catch (Exception ex) {
                prt.PRValue = 0;
                ValueErrorLabel.Text = "Value must a number";
            }
            
        }

        protected void PTAddButton_Click(object sender, EventArgs e)
        {
            property_type_table ptt = new property_type_table();
            String name = PTNameTxt.Text;
            String desc = PTDescTxt.Text;

            ptt.PTID = Guid.NewGuid().ToString();
            ptt.PTName = name;
            ptt.PTDesc = desc;
            dcdc.property_type_tables.InsertOnSubmit(ptt);
            dcdc.SubmitChanges();
            GridView2.DataBind();
        }

        protected void WTBAddButton_Click(object sender, EventArgs e)
        {
            when_to_buy wtb = new when_to_buy();
            wtb.WTBID = Guid.NewGuid().ToString();
            wtb.WTBName = WTBNameTxt.Text;
            wtb.WTBDesc = WTBDescTxt.Text;
            dcdc.when_to_buys.InsertOnSubmit(wtb);
            dcdc.SubmitChanges();
            GridView3.DataBind();
        }

        protected void LTAddButton_Click(object sender, EventArgs e)
        {
            loan_type_table ltt = new loan_type_table();
            ltt.LTID = Guid.NewGuid().ToString();
            ltt.LTName = LTNameTxt.Text;
            ltt.LTDesc = LTDescTxt.Text;
            dcdc.loan_type_tables.InsertOnSubmit(ltt);
            dcdc.SubmitChanges();
            GridView4.DataBind();
        }

    }
}